The memory pool is a static memory management method. It divides a fixed continuous memory area into several blocks of different sizes in advance. When applying, the user gives the corresponding memory block to him. The advantage of this method is
simple modifications based on alloc.
The Memory Pool Design Scheme of mempool is as follows (you can also refer to the in-depth analysis of STL by Hou Jie)
Apply for a large heap memory from the system, divide blocks of different sizes on the memory, and connect blocks of the same size to form a linked list. For example, a chunks of the size of a constitute the linked list L. When applying for a large hour, the chunk is directly obtained from the lin
After reading the rewrite, I read it again without knowing it. I didn't consider multithreading in it. I mainly wanted to implement the following memory pool.
Mempool. h
#ifndef MEMPOOL_H_#define MEMPOOL_H_#include
Mempool. cpp
# Include "mempool. H "namespace flysnow {char * mempool: start_pool = 0; char *
,FREEBSD7 per 2k,4) Code implementation:struct Memblock{int used;void* data;struct memblock* next;struct memblock* createnext;} ; struct Mempool{int size; Memblock sizeint unused; Idle Memblock sizeint datasize; The size of each allocated data (that is, memblock.data)struct Memblock * free_linkhead; Idle Memblock Linked table headerstruct Memblock * create_linkhead; All created Memblock linked header, memory pool released when used to prevent the memo
Http://note.youdao.com/share? Id = 248a6e3b877213484a02b507
F69ccf84 type = Note
The Sina Blog link, http://blog.sina.com.cn/s/blog_6b0d60af0101cu1z.html
Octeon is designed for packet processing and provides a large number of hardware acceleration units. Its chip design team designed the alpha chip, which is also well-developed in the processor design. Dpdk is a package processing software solution in intel X86 architecture and Linux environment. In summary, there are several main aspects: har
Simple memory pool implementation
# Include
# Include
# Include
# Include
Using namespace std; class MemPool {struct FreeNode * next;}; private: static const int allocNum = 8; static const int step = 4; static char * head; static char * tail; static unsigned int poolSize; static int allocSize [allocNum]; static FreeNode * FreeList [allocNum]; static void * GetFromPool (int n ); static void * PoolAlloc (int n, int num);
range),
5-8 bytes to store the ID of the next available chunk.
Then it adds the struct memblock * pnextblock; pointer. When nfree is 0 or the memblock of the index is no longer available for chunk, malloc adds a new memblock and hangs it behind it (one-way linked list ).
2. memblok management mempool
Typedef struct mempool{
Memblock * freeblock [max_index];Char * pmemory;}
*, unsigned long))void *kmem_cache_alloc (struct kmem_cache *c, gfp_t flags)Kmem_cache_create/kmem_cache_alloc is a kind of memory allocation method based on slab allocator, which is suitable for repeatedly allocating the same size memory block (can be less than the page size). First create a cache area with Kmem_cache_create, and then use Kmem_cache_alloc to get the new memory block from the cache area. Kmem_cache_alloc the maximum amount of memory that can be allocated at one time is defined
This article has been migrated to: http://cpp.winxgui.com/cn:dive-into-memory-pool
Overview
Mempool technology is highly respected. I searched by Google and did not find a detailed article on principles. Therefore, I would like to add one. In addition, boost: The difference between the pool component and the classic mempool is added. The Application of mempool i
use of internal pages, in some cases, the kernel also needs to allocate a space of any size, as the user program uses malloc. This feature is implemented by the slab system. slab is equivalent to creating object pools for some of the structure objects commonly used in the kernel, such as pools for task structures, pools corresponding to mm structures, and so on. Slab also maintains a common pool of objects, such as the "32-byte-Size" object pool, the "64-byte-Size" object pool, and so on. The K
of the locations in the interval has been updated.So just modify each point on the path of the segment tree to modify it.So we maintain two markers: a mark and B mark.The a tag is precisely overwritten at each corresponding node on the line tree at the time of the modification, and the query needs to be queried for all nodes on the path to the root of all the corresponding nodes.The b tag is exactly the oppositeThat's all.#include #include #include #include #define M 1010using namespace STD;int
kmem_cache *c, gfp_t flags)Kmem_cache_create/kmem_cache_alloc is a memory allocation method based on the slab allocator, which is suitable for repeatedly allocating the same size memory blocks (which can be smaller than the page size). First create a cache area with Kmem_cache_create, and then use Kmem_cache_alloc to get a new block of memory from the cache area. Kmem_cache_alloc The maximum memory that can be allocated at a time is defined by the Max_obj_order macro in the Mm/slab.c file, whic
checks whether the pointer is available, whether it is alias, and whether it is in use. When this keyword is used, the compiler will not check the information. Noalias means that the function call cannot modify or reference the visible global state and only modifies the memory directly pointed to by the pointer parameter. If a function specifies the noalias keyword, the optimizer determines that, in addition to the inherent parameters, only the first level of the parameter pointer is indirectly
The Memery pool technique is to apply a certain number of memory blocks that are equal in size (typically) to be reserved before actually using memory. When there is a new memory requirement, a portion of the memory block is separated from the memory pool, and if the memory block is not enough, then continue to request new memory. One notable advantage of this is that memory fragmentation is avoided as much as possible, resulting in improved memory allocation efficiency.Not only is it widely use
descriptionStatic pool mempool; // airplanes Memory Pool
};
Inline void * airplane: Operator new (size_t size){Return mempool. alloc (size );}
Inline void airplane: Operator Delete (void * P,Size_t size){Mempool. Free (p, size );}
// Create a memory pool for the airplane object,// Implemented in the class implementation filePool airplane:
memory management functions in the airplane class:
Class airplane {Public:
... // General airplane Function
Static void * operator new (size_t size );Static void operator Delete (void * P, size_t size );
PRIVATE:Airplanerep * rep; // pointer to the actual descriptionStatic pool mempool; // airplanes Memory Pool
};
Inline void * airplane: Operator new (size_t size){Return mempool. alloc (size );}
Inline voi
slab, mempool (memory pool) is introduced in Linux 2.6 ). The intention is: we do not want some objects to be allocated due to insufficient memory, so we allocate several objects in advance and store them in mempool. Normally, resources in mempool are not moved when an object is allocated, and are allocated through slab as usual.
Topic: Given Strings A and b, the shortest substring/sub-sequence s satisfies S is not a substring/sub-sequence of bThat's a really toxic problem.Pointers is similar to this problemThen the substring is the suffix automatic machine sequence is naturally the sequence automaton = =Every time an X node is updated, any subsequent nodes of X are connected to this nodeThe parent of each node is where the letter last appearedEach letter records the last occurrence of the position when the pointer is up
Bare two-dimensional line tree ... Find rectangle maximum and rectangle overlayThe board is more troublesome to knock up Qaq1 /**************************************************************2 problem:15133 User:rausen4 language:c++5 result:accepted6 time:24884 Ms7 memory:127268 KB8 ****************************************************************/9 Ten#include One#include A - using namespacestd; - theInlineintread (); - - intN, M; - + structSEGX { -SEGX *ls, *rs; + intMX, tag; A
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.